﻿<Window x:Name="_mainWindow"
	x:Class="Intuipic.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:Intuipic"
	xmlns:nav="clr-namespace:Intuipic.Navigation"
	xmlns:con="http://schemas.kent.boogaart.com/converters" 
	xmlns:converters="clr-namespace:Intuipic.Converters"
	xmlns:data="clr-namespace:Intuipic.Data"
	xmlns:sys="clr-namespace:System;assembly=mscorlib"
	xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="PresentationOptions"
    Title="Intuipic"
	WindowState="Maximized"
	Mouse.MouseMove="Window_MouseMove" 
	DataContext="{Binding RelativeSource={RelativeSource Self}}"
	Closed="Window_Closed"
	Closing="Window_Closing"
	Style="{StaticResource {x:Type Window}}"
	WindowStyle="None">
	<Window.Resources>
		<converters:BitmapFrameConverter x:Key="BitmapFrameConverter" DecodePixelWidth="{x:Static SystemParameters.PrimaryScreenWidth}"/>

		<converters:BitmapOrientationConverter x:Key="BitmapOrientationConverter"/>

		<con:MapConverter x:Key="CrossVisibilityConverter">
			<con:Mapping To="{x:Static Visibility.Visible}">
				<con:Mapping.From>
					<sys:Boolean>True</sys:Boolean>
				</con:Mapping.From>
			</con:Mapping>
		</con:MapConverter>

		<con:MapConverter x:Key="NoFilesVisibilityConverter">
			<con:Mapping To="{x:Static Visibility.Visible}">
				<con:Mapping.From>
					<sys:Boolean>False</sys:Boolean>
				</con:Mapping.From>
			</con:Mapping>
		</con:MapConverter>
	</Window.Resources>
	
	<Window.CommandBindings>
		<CommandBinding Command="local:Commands.ChooseFolders" Executed="ChooseFolders"/>
		<CommandBinding Command="local:Commands.CycleDisplayOrder" Executed="CycleDisplayOrder"/>
		<CommandBinding Command="local:Commands.Information" Executed="Information"/>
		<CommandBinding Command="local:Commands.PausePlay" Executed="PausePlay" CanExecute="PausePlay_CanExecute"/>
		<CommandBinding Command="local:Commands.IncreaseDelay" Executed="IncreaseDelay"/>
		<CommandBinding Command="local:Commands.DecreaseDelay" Executed="DecreaseDelay"/>
		<CommandBinding Command="local:Commands.Previous" Executed="Previous" CanExecute="Previous_CanExecute"/>
		<CommandBinding Command="local:Commands.Next" Executed="Next" CanExecute="Next_CanExecute"/>
		<CommandBinding Command="local:Commands.MarkAsDeleted" Executed="MarkAsDeleted" CanExecute="MarkAsDeleted_CanExecute"/>
		<CommandBinding Command="local:Commands.Minimize" Executed="Minimize"/>
		<CommandBinding Command="local:Commands.Close" Executed="Close"/>
	</Window.CommandBindings>
	
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*"/>
		</Grid.ColumnDefinitions>

		<!-- this is the main navigation area -->
		<DockPanel Panel.ZIndex="1" Background="#00ffffff">
			<DockPanel.Triggers>
				<!-- animating NavigationPercentageVisible effectively hides and shows the navigation -->
				<EventTrigger RoutedEvent="Control.MouseEnter">
					<BeginStoryboard>
						<Storyboard TargetProperty="NavigationPercentageVisible" TargetName="_mainWindow">
							<DoubleAnimation To="1" Duration="0:0:.5"/>
						</Storyboard>
					</BeginStoryboard>
				</EventTrigger>
				<EventTrigger RoutedEvent="Control.MouseLeave">
					<BeginStoryboard>
						<Storyboard TargetProperty="NavigationPercentageVisible" TargetName="_mainWindow">
							<DoubleAnimation To="0" Duration="0:0:.5"/>
						</Storyboard>
					</BeginStoryboard>
				</EventTrigger>
			</DockPanel.Triggers>
			
			<nav:Panel x:Name="_navigation" HorizontalContentAlignment="Center">
				<nav:Panel.Margin>
					<MultiBinding Converter="{StaticResource NavigationMarginConverter}">
						<Binding Path="Settings.PinOptions"/>
						<Binding Path="IsFolderSelectionOpen" ElementName="_navigation" Mode="OneWay"/>
						<Binding Path="NavigationPercentageVisible"/>
						<Binding Path="ActualHeight" ElementName="_navigation" Mode="OneWay"/>
					</MultiBinding>
				</nav:Panel.Margin>
				<nav:Panel.Opacity>
					<MultiBinding Converter="{StaticResource NavigationOpacityConverter}">
						<Binding Path="Settings.PinOptions"/>
						<Binding Path="IsFolderSelectionOpen" ElementName="_navigation" Mode="OneWay"/>
						<Binding Path="NavigationPercentageVisible"/>
					</MultiBinding>
				</nav:Panel.Opacity>
				<nav:Panel.IsImageCyclingEnabled>
					<MultiBinding>
						<MultiBinding.Converter>
							<con:ExpressionConverterExtension>
								<con:ExpressionConverterExtension.Expression>
									<![CDATA[
									{0} && {1}
									]]>
								</con:ExpressionConverterExtension.Expression>
							</con:ExpressionConverterExtension>
						</MultiBinding.Converter>
						<Binding Path="IsImageCyclingEnabled"/>
						<Binding Path="FileEnumerator.HasFiles" Mode="OneWay"/>
					</MultiBinding>
				</nav:Panel.IsImageCyclingEnabled>
			</nav:Panel>
		</DockPanel>

		<!-- this dock panel contains the image being displayed -->
		<Grid Grid.Row="0" Grid.RowSpan="2" Style="{StaticResource ImagePanelStyle}" Focusable="True">
			<Grid.FocusVisualStyle>
				<!-- intentionally empty because we want the grid to accept focus but not show it in any way -->
				<Style/>
			</Grid.FocusVisualStyle>
			
			<Grid.CommandBindings>
				<CommandBinding Command="local:Commands.Previous" Executed="Previous"/>
				<CommandBinding Command="local:Commands.Next" Executed="Next"/>
			</Grid.CommandBindings>

			<Image x:Name="_image" Source="{Binding FileEnumerator.Current, Mode=OneWay, Converter={StaticResource BitmapFrameConverter}}">
				<Image.LayoutTransform>
					<RotateTransform Angle="{Binding FileEnumerator.Current, Mode=OneWay, Converter={StaticResource BitmapOrientationConverter}}"/>
				</Image.LayoutTransform>
			</Image>
			<Image Visibility="{Binding IsCurrentFileMarkedForDeletion, Converter={StaticResource CrossVisibilityConverter}, FallbackValue=Hidden}" Opacity="0.5">
				<Image.Source>
					<DrawingImage>
						<DrawingImage.Drawing>
							<DrawingGroup PresentationOptions:Freeze="True">
								<DrawingGroup.Children>
									<!-- Mark as Deleted/<Compound Path> -->
									<GeometryDrawing Brush="#ffe03332" Geometry="F1 M 114.488770,114.488770 C 80.963379,148.014160 62.500000,192.587891 62.500000,240.000000 C 62.500000,287.412109 80.963379,331.986328 114.488770,365.511719 C 148.013672,399.037109 192.587891,417.500000 240.000000,417.500000 C 287.412109,417.500000 331.986328,399.037109 365.511719,365.511719 C 399.037109,331.986328 417.500000,287.412109 417.500000,240.000000 C 417.500000,142.125977 337.874023,62.500000 240.000000,62.500000 C 192.587891,62.500000 148.014160,80.963379 114.488770,114.488770 Z M 477.500000,240.000000 C 477.500000,371.167969 371.167969,477.500000 240.000000,477.500000 C 108.832520,477.500000 2.500000,371.167969 2.500000,240.000000 C 2.500000,108.832520 108.832520,2.500000 240.000000,2.500000 C 371.167969,2.500000 477.500000,108.832520 477.500000,240.000000 Z">
										<GeometryDrawing.Pen>
											<Pen DashCap="Flat" Thickness="5.000000" Brush="#ff221e1f" MiterLimit="1.000000"/>
										</GeometryDrawing.Pen>
									</GeometryDrawing>

									<!-- Mark as Deleted/<Path> -->
									<GeometryDrawing Brush="#ffe03332" Geometry="F1 M 385.750000,275.000000 L 91.250000,275.000000 L 91.250000,205.000000 L 385.750000,205.000000 L 385.750000,275.000000 Z">
										<GeometryDrawing.Pen>
											<Pen DashCap="Flat" Thickness="5.000000" Brush="#ff221e1f" MiterLimit="1.000000"/>
										</GeometryDrawing.Pen>
									</GeometryDrawing>
								</DrawingGroup.Children>
							</DrawingGroup>
						</DrawingImage.Drawing>
					</DrawingImage>
				</Image.Source>
			</Image>
		</Grid>

		<!-- this dock panel is displayed when a message needs to be displayed -->
		<DockPanel Grid.Row="0" Grid.RowSpan="2" Visibility="{Binding FileEnumerator.HasFiles, Converter={StaticResource NoFilesVisibilityConverter}, FallbackValue=Hidden}" Style="{StaticResource MessagePanelStyle}">
			<TextBlock Style="{StaticResource MessageStyle}">
				No images could be found. You can click <Hyperlink x:Name="_openFoldersHyperlink" Style="{StaticResource MessageHyperlinkStyle}" Click="_openFoldersHyperlink_Click">here</Hyperlink> to select the source of your images.
			</TextBlock>
		</DockPanel>
	</Grid>
</Window>
